using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;


public class FileTools
{
    public static string ReadTxt(string pathFile)
    {
        return File.ReadAllText(pathFile);
    }

    public static void WriteTxt(string pathFile, string strTxt)
    {
        File.WriteAllText(pathFile, strTxt);
        return;
    }

    public static void DeleteTxt(string pathFile)
    {
        File.Delete(pathFile);
        return;
    }

    public static string StringKeyValue(string content, string key, string symbol_begin, string symbol_end, int startIndex=0)
    {
        int index_key_begin = content.IndexOf(key, startIndex);
        int index_symbol_begin = content.IndexOf(symbol_begin, index_key_begin);
        int index_symbol_end = content.IndexOf(symbol_end, index_symbol_begin);
        return content.Substring(index_symbol_begin+1, index_symbol_end - index_symbol_begin - 1);
    }

    public static string StringValue(string content, string symbol, ref int nextIndex)
    {
        int startIndex = nextIndex;
        nextIndex = content.IndexOf(symbol, startIndex);

        string resultTx = "";
        if(nextIndex > 0)
        {
            resultTx = content.Substring(startIndex, nextIndex - startIndex);
        }
        else
        {
            Debug.Log("content.Length:"+ content.Length+ " nextIndex:"+ nextIndex);
            resultTx = content.Substring(startIndex, content.Length - startIndex);
        }
        nextIndex++;

        return resultTx;
    }
}
